package org.tvolkov.mycompany



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Project)
@Mock([Company, Division, Project])
class ProjectTests {

    void testGetAllProjects() {
       def cmp1 = new Company(name: "company");
	   def div1 = new Division(name: "division", company: cmp1);
	   def prj1 = new Project(name: "project1", customer: "c1", deadline: new Date(), division: div1).save();
	   def prj2 = new Project(name: "project2", customer: "c2", deadline: new Date(), division: div1).save();
	   def prj3 = new Project(name: "project3", customer: "c3", deadline: new Date(), division: div1).save();
	   
	   def data = new ProjectService().getAllProjects();
	   assertEquals "project1", data[0].text;
	   assertEquals "1", data[0].id;
	   assertEquals "project2", data[1].text;
	   assertEquals "2", data[1].id;
	   assertEquals "project3", data[2].text;
	   assertEquals "3", data[2].id;
    }
}
